<?php

ini_set('display_errors',true);
session_start();

$left="../templates/misc/menu.php";
$data="../templates/account.php";
$userInfo = "../templates/misc/userInfo.php";
$u = new SimpleXMLElement($_SESSION['user']);

$alert = "";
	
if (isset($_POST)) {
	
	if ( md5($_POST['pwd']) == $u->pwd ) {
		
		// loads Users file and change values
		$userList = simplexml_load_file('../xmldata/users.xml');
		
		$tmp = $userList->xpath("//user[@uid='" .(String) $u['uid']. "']");
		$user = $tmp[0]; 
		
		$user->lastname = $_POST['lastname'];
		$user->firstname = $_POST['firstname'];
		$user->email = $_POST['email'];
		$user->organzation = $_POST['organzation'];
		if ($_POST['new_pwd'] != "" && ($_POST['new_pwd'] == $_POST['new_pwd_2']) ) {
			$user->pwd = md5($_POST['new_pwd']);
		} else {
			$alert .= "Password NOT changed.  New pwd and confirm pwd did not match.";
		}
		$u = $user;
				
		// save new values to file
		$f = fopen( "../xmldata/users.xml", "w");
		if (fwrite($f, $userList->asXML()) === FALSE) {
			print "Houston, We've got a problem ...";
			exit;
		}
		fclose($f);
		$_SESSION['user'] = $u->asXML();
		$confirm = "Password modifié.";
		
	} else {
		$alert = "Password invalide.";
	}
	
}

include("../templates/main.php");

?>
